package com.apes.framework.plugin.workflow.parser.node;

import com.apes.framework.plugin.filereader.xml.AbstractNodeParser;
import com.apes.framework.plugin.filereader.xml.ApesElement;
import com.apes.framework.plugin.workflow.parser.model.Workflow;
import org.dom4j.Element;
import org.springframework.stereotype.Component;

/**
 * 功能：process 节点解析器
 *
 * @author xul
 * @create 2018-04-18 11:42
 */
@Component
public class WorkflowNodeParser extends AbstractNodeParser {



    /**
     * 可解析的节点列表
     **/
    private final String[] nodeNames = {"workflow"};

    /**
     * 可解析节点域
     **/
    public static final String domain = "workflow";


    /**
     * 功能：可解析节点域
     */
    @Override
    public String getDomain() {
        return domain;
    }

    /**
     * 功能：可解析的根节点列表
     */
    @Override
    public String[] getNames() {
        return nodeNames;
    }

    /**
     * 功能：解析节点
     *
     * @param node
     */
    @Override
    public ApesElement parse(Element node) {
        ApesElement element = super.parse(node);
        if(element == null) return null;
        Workflow.addWorkflow(element.getAttribute("id"), element.parse());
        return element;
    }
}
